package com.lst.api.vo;

import com.lst.api.constant.ApplyTypeEnum;
import com.lst.api.entity.ApplyInfo;
import com.lst.api.exception.RequestParamErrorException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
 * 借款数据信息表
 *
 * @author Frank
 * @date 2019-12-30 10:31:37
 * @version: V1.0
 */
@Data
@NoArgsConstructor
public class ApplyInfoVo implements Serializable {
    private static final long serialVersionUID = 1L;

    @ApiModelProperty(name = "applyType", value = "申请类型   1:个人   2:企业", required = true, dataType = "String")
    private String applyType;

    @ApiModelProperty(name = "loanPurposeId", value = "用途id", required = true, dataType = "Long")
    private Long loanPurposeId;

    @ApiModelProperty(name = "loanPurposeOther", value = "其他用途", dataType = "String")
    private String loanPurposeOther;

    public ApplyInfoVo(ApplyInfo applyInfo) {
        if (applyInfo == null) {
            return;
        }
        this.applyType = applyInfo.getApplyType();
        this.loanPurposeId = applyInfo.getLoanPurposeId();
        this.loanPurposeOther = applyInfo.getLoanPurposeOther();
    }

    public void check() {
        ApplyTypeEnum applyTypeEnum = ApplyTypeEnum.getByKey(this.applyType);
        boolean check = applyTypeEnum != null && this.loanPurposeId != null;
        if (!check) {
            throw new RequestParamErrorException("ApplyInfo请求参数不合法！");
        }
    }
}